/*
* (c) 2014 University of Applied Sciences, Karlsruhe
* Project "Segmentation of depth data of a plenoptic camera"
* summer semester 2014
*
* contour_3d.h
* This file contains a class to represent object contours in 3D space.
*/

#ifndef _CONTOUR_3D_H_
#define _CONTOUR_3D_H_

#include <vector>
#include <opencv2/opencv.hpp>

#include "sgMain/3d/fit_line_3d.h"

namespace sgMain
{
	/**
	This class is used to represent object contours in a 3D environment. Each contour is based on a set of lines, which, projected onto the image plane,
	form a consecutive line set. The 3D contours are generated by applying a fitting algorithm onto a 2D line set and a depth map.
	*/
	class Contour3D
	{
	public:
		std::vector<std::shared_ptr<sgMain::FitLine3D>> contourLines; /// List of 3D contours.

		/**
		Function to match the begin- and end points of the lines belonging to this contour. It ensures that the end point of the previous line has the same
		coordinates as the begin point of the next line. Immediately after the fitting process, this might not be the case since each line is fitted separately.
		This function therefore choses the middle point between the end point of the previous line and the begin point of the next line and replaces both points by
		the middle point.
		\param[in] intrinsicParameters The matrix of intrinsic paramters, necessary to project the 3D contours onto the flat image.
		*/
		int PostprocessContours(const cv::Mat &intrinsicParameters);

		/**
		Displays the current contour in a 3D viewport.
		\param[in] viewport3D The viewport onto which this contour should be displayed.
		\param[in] contourIndex The index of this contour. Ensure that each contour added to the viewport has a different index!
		*/
		void Render(Visualization3D &viewport3D, int contourIndex) const;
	};

	/**
	Stream output operator.
	*/
	std::ostream& operator<< (std::ostream& stream, const Contour3D &contour3D);
}

#endif